package com.chinasoft.mall.activity.adapter;

import java.util.List;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.chinasoft.mall.R;
import com.chinasoft.mall.activity.MainActivity;
import com.chinasoft.mall.model.response.GoodsClassBean;

public class SpAdapter extends BaseAdapter {
	private List<GoodsClassBean> dds;
	private LayoutInflater inflater;
	private ViewHolder _vh;
	private int[] images = { R.drawable.class_1, R.drawable.class_2,
			R.drawable.class_3, R.drawable.class_4, R.drawable.class_5,
			R.drawable.class_6, R.drawable.class_7, R.drawable.class_8,
			R.drawable.class_9, R.drawable.class_10, R.drawable.class_11, };

	public SpAdapter(MainActivity MainActivity, List<GoodsClassBean> crs) {
		inflater = LayoutInflater.from(MainActivity);
		this.dds = crs;
	}

	public void setData(List<GoodsClassBean> crs) {
		this.dds = crs;
		this.notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		if (dds == null) {
			return 0;
		} else {
			return dds.size();
		}
	}

	@Override
	public Object getItem(int position) {
		if (dds == null) {
			return null;
		} else {
			return dds.get(position);
		}
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.splv, null);
			_vh = new ViewHolder();
			_vh.splv = (TextView) convertView.findViewById(R.id.splv);
			_vh.spimg = (ImageView) convertView.findViewById(R.id.spimg);
			convertView.setTag(_vh);
		} else {
			_vh = (ViewHolder) convertView.getTag();
		}
		GoodsClassBean _dd = dds.get(position);
		_vh.splv.setText(_dd.getCLASS_NAME());
		if (images.length > position) {
			_vh.spimg.setImageResource(images[position]);
		}
		return convertView;
	}


	class ViewHolder {
		public TextView splv;
		public ImageView spimg;
	}
}
